package cdu.sl.controller;

import cdu.sl.common.domain.Result;
import cdu.sl.domain.dto.FolderCreateDTO;
import cdu.sl.domain.dto.FolderUpdateDTO;
import cdu.sl.domain.vo.FolderVO;
import cdu.sl.service.FolderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件夹控制器
 */
@Api(tags = "文件夹接口")
@Slf4j
@RestController
@RequestMapping("/folders")
@RequiredArgsConstructor
public class FolderController {

    private final FolderService folderService;

    /**
     * 创建文件夹
     * @param folderCreateDTO 创建文件夹表单对象
     * @return
     */
    @ApiOperation("创建文件夹")
    @PostMapping
    public Result createFolder(@RequestBody FolderCreateDTO folderCreateDTO) {
        log.info("创建文件夹：{}",folderCreateDTO);
        folderService.createFolder(folderCreateDTO);
        return Result.success();
    }

    /**
     * 获取用户的所有文件夹
     */
    @GetMapping
    @ApiOperation("获取用户的所有文件夹")
    public Result<List<FolderVO>> getCurrentUserFolder(){
        log.info("获取用户所有文件夹...");
        List<FolderVO> folderVOList=folderService.getCurrentUserFolder();
        return Result.success(folderVOList);
    }


    /**
     * 更新文件夹信息
     * @param folderUpdateDTO 文件夹更新DTO
     */
    @PutMapping
    @ApiOperation("更新文件夹信息")
    public Result<Void> updateFolder(@RequestBody @Validated FolderUpdateDTO folderUpdateDTO){
        log.info("更新文件夹信息:{}",folderUpdateDTO);
        folderService.updateFolder(folderUpdateDTO);
        return Result.success();
    }


    /**
     * 获取文件夹详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("获取某个文件夹详情")
    public Result<FolderVO> getFolderById(@PathVariable Long id){
        log.info("根据id：{}获取文件夹详情",id);
        FolderVO folderVO=folderService.getFolderById(id);
        return Result.success(folderVO);
    }


    /**
     * 删除指定文件夹
     * @param id 文件夹id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除指定文件夹")
    public Result<Void> deleteFolder(@PathVariable Long id){
        log.info("根据id：{}删除指定文件夹",id);
        folderService.deleteFolder(id);
        return Result.success();
    }





}
